import sys

from PyQt6 import uic
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QFrame, QApplication, QProgressBar, QLabel, QPushButton


class ProcessingBox:
    def __init__(self, path: str = './UI/processing.ui'):
        self.__button = None
        self.__tittle = None
        self.__processor = None
        self.offset = None
        self.e = None

        self.ui: QFrame = uic.loadUi(path)
        self.res = 0
        self.initUi()

    def close(self):
        self.ui.close()

    def callback(self):
        self.close_ui()
        if self.res == 0:
            self.res = 1
        return self.res

    def set_offset(self, val: int):
        self.offset = val

    def set_value(self):
        self.processor: QProgressBar
        self.__processor.setValue(self.__processor.value() + self.offset)

    def show(self):
        self.ui.show()

    def close_ui(self):
        self.ui.close()

    def initUi(self):
        # 禁止头部内容
        self.ui.setWindowFlags(Qt.WindowType.WindowTitleHint)
        # 获取进度条
        self.__processor: QProgressBar = self.ui.findChild(QProgressBar, "progressBar")
        # 获取标题
        self.__tittle: QLabel = self.ui.findChild(QLabel, "label")

        self.__button: QPushButton = self.ui.findChild(QPushButton, "pushButton")
        # 设置图标
        self.ui.setWindowIcon(QIcon("./FormatRecovery.ico"))

        self.ui.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    p = ProcessingBox('../UI/processing.ui')
    p.set_offset(1)
    p.set_value()
    p.show()
    sys.exit(app.exec())
